package br.project.cdd.presentation;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.project.cdd.vo.PermissaoVO;
import br.project.cdd.vo.TelasVO;
import br.project.cdd.bean.TelasBean;;

public class PerfilServlet extends HttpServlet {
	
	@Override
	public void service(HttpServletRequest request, HttpServletResponse response){
		
		TelasVO telaVo = new TelasVO();
		ArrayList<TelasBean> listBean = telaVo.getTodasTelas();
		ArrayList<String> idsTela = new ArrayList<String>();
		
		int idPerfil = Integer.parseInt(request.getParameter("ddlPerfil"));
		
		for (int i = 0; i < listBean.size(); i++) {
			if (request.getParameter("ckbTela" + String.valueOf(listBean.get(i).getId_tela())) != null)
			{
				idsTela.add(request.getParameter("ckbTela" + String.valueOf(listBean.get(i).getId_tela())));
			}
		}
		
		PermissaoVO permVo = new PermissaoVO();
		permVo.inserirPermissao(idsTela, idPerfil);
		
		try{
			response.sendRedirect("index.jsp");
		}
		catch(IOException io){
			io.printStackTrace();
		}
		
	}
}
